package com.rest.demo.Service;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.rest.demo.util.NewRestUtil;
import com.rest.demo.util.restUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;




public class DysmtXxjj {


    private restUtil XRestUtil;

    public String get2 (String  Api,String request){
String Url =Api+"?request="+request;
System.out.println(Url);
        NewRestUtil.get(Url,String.class);
return NewRestUtil.post(Url,String.class).getBody();
    }

    RestTemplate restTemplate = new RestTemplate();



    public String PostformData( String Api,String request) throws JSONException {
//        // 请求地址
//        String url = Api;

//        // 封装参数，千万不要替换为Map与HashMap，否则参数无法传递
//        Map<String,String> map = new HashMap<>();
//        MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
//        paramMap.add("request", request);
       // RestTemplate restTemplate = new RestTemplate();
        //        System.out.println("result1==================" + paramMap);
        // 1、使用postForObject请求接口

        ResponseEntity<String> responseEntity = restTemplate.postForEntity(Api,"request="+request, String.class);
        String Token = JSONObject.parseObject(responseEntity.getBody()).getString("Content");
        return Token;

//       return new RestTemplate().postForEntity(Api,"request="+request, String.class).getBody();

    }

    public JSONObject PostDataInfo(String Api,String request){

        ResponseEntity<String> responseEntity = restTemplate.postForEntity(Api,"request="+request, String.class);
        JSONObject Token = JSONObject.parseObject(responseEntity.getBody());
        return Token;
    }





}


